package com.ged.family1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class familyTree1 {

	/**
	 * Agile Method Project 1
	 */
	public static void main(String[] args) {
		
		HashMap<String, String> hValidTags = new HashMap<String, String>();
		
		populateValidTags(hValidTags);
		
		try{
			final String sInvalidTag = "Invalid tag";
			
			//BufferedReader reader = new BufferedReader(new FileReader("C:/Users/Ronny/Documents/STEVENS INSTITUTE OF TECHNOLOGY - LECTURES/Software Agile Development/GED/My-Family-8-Sep-2013.ged"));
			BufferedReader reader = new BufferedReader(new FileReader("C:/Users/Ronny/Documents/STEVENS INSTITUTE OF TECHNOLOGY - LECTURES/Software Agile Development/week1/GEDCOMTorture.ged"));

			
			String line = null;
			String[] parts ;
			String tagValue="";
			
			String sB_Date = "";
			String sD_Date = "";
			
			DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 
		    Date bDate = new Date();
		    Date dDate = new Date(); 

			
			while ((line = reader.readLine()) != null) {
			    
				System.out.println("-----------------------------");
				System.out.println(line);
				parts = line.split(" ");
				
				for ( int i = 0 ; i < parts.length ; i++){
					
					
					
					if(i==0){
						
						
						System.out.println(parts[i]);
						
						if(parts[i].equals("0")){
							System.out.println("-----NEW PERSON----------------------------");
						}
						
						
					
					}else if(i==1 ){

						try{
							
							//validate the tag
							tagValue = hValidTags.get(parts[i]);

							if(tagValue == null){
								System.out.println(sInvalidTag);
							}
							else{
								System.out.println(parts[i]);
							}
							
						}
						catch(Exception e){
							e.printStackTrace();
							continue;
						}
						
					}
					
					
					
				}
			}
		}
		catch(Exception e){
			
			e.printStackTrace();
			
		}

	}
	
	static final void populateValidTags(HashMap<String, String> hm){		
		
		hm.put("INDI", "valid");
		hm.put("NAME", "valid");
		hm.put("SEX", "valid");
		hm.put("BIRT", "valid");
		hm.put("DEAT", "valid");
		hm.put("FAMC", "valid");
		hm.put("FAMS", "valid");
		hm.put("FAM", "valid");
		hm.put("MARR", "valid");
		hm.put("HUSB", "valid");
		hm.put("WIFE", "valid");
		hm.put("CHIL", "valid");
		hm.put("DIV", "valid");
		hm.put("DATE", "valid");
		hm.put("TRLR", "valid");
		hm.put("NOTE", "valid");
	}
	

}
